package com.chinanet.repository.faultanticipate;


import com.chinanet.entry.faultanticipate.Operation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RestResource;

public interface OperationRepository extends PagingAndSortingRepository<Operation, Long> {
    @RestResource(path = "record",rel = "record")
    @Query(value = "select * from operation where record_id=:recordId", nativeQuery = true)
    Page<Operation> getAllByRecord(@Param("recordId") long recordId, Pageable pageable);

    @RestResource(path = "branch",rel = "branch")
    @Query(value = "select * from operation o left join record r on r.id=o.record_id left join branch b on b.id=r.branch_id where b.id=:branchId order by o.last_modified_at desc", nativeQuery = true)
    Page<Operation> getAllByBranch(@Param("branchId") long branchId, Pageable pageable);
}